//index.js
//获取应用实例
const request = require('../../utils/request')
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    swiper: [],
    menu: [],
    list: [
      "../../images/list/link-01.png",
      "../../images/list/link-02.png",
    ],
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  toList: function (event) {
    console.log(event)
    wx.navigateTo({
      url: '../list/list'
    })
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
      request('/slides')
      .then(res => {
        this.setData({
          swiper: res.data,
        })
      }).catch(error=>{
        console.log(error)
      })

      request('/categories')
      .then(res => {
        this.setData({
          menu: res.data,
        })
      }).catch(error=>{
        console.log(error)
      })
  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})